home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3231 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: MFC 4.0 OnDraw and DC question
  5. Date: 22 Jan 1996 22:32:31 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4e139v$oa9@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 22, 1996 11:50:29 in article <MFC 4.0 OnDraw and DC question>, 'Pete
  15. Olpe <olpe@ep.com>' wrote: 
  16.  
  17.  
  18. >In my "OnDraw(CDC* pDC)" routine I call another member function that  
  19. >performs the actual work of drawing. I pass it the pointer to the DC that 
  20.  
  21. >was passed to the OnDraw() routine.  It is slow, and eventually bombs by  
  22. >failing to create a font, or brush, or whatever.  A very simplified  
  23. >version of the code follows: 
  24. >myClass::OnDraw(CDC* pDC) 
  25. >{ 
  26. >myDrawRoutine(pDC); 
  27. >} 
  28. >myClass::myDrawRoutine(CDC* pDC) 
  29. >{ 
  30. >create fonts, brushes, pens; 
  31. >pDC->SelectObject(fonts, brushes, pens, etc); 
  32. >pDC->DrawText(...); 
  33. >} 
  34. >When I substitute the code for "myDrawRoutine" back inline in the  
  35. >"OnDraw" routine, the drawing speeds up and never seems to bomb by  
  36. >failing to create an object or select an object into the DC. 
  37. >Does anyone have any ideas why splitting out the code from an "OnDraw"  
  38. >routine would not work? 
  39. Often when people post code that is "similar" or "essentially the same" 
  40. some key piece is left out.  I suspect that this might be the case as 
  41. there's no reason that an extra function call would cause such slowdown. 
  42.  
  43. The part of your code that could conceivably be the choking point 
  44. in your program is the creation of fonts and brushes on every call 
  45. to OnDraw.  But that should occur the same whether you are calling 
  46. myDrawRoutine or inserting the same code into OnDraw.  I think that, 
  47. unless some unusual circumstance prevents it, construct your 
  48. brushes and fonts once and then keep them around for reuse 
  49. until the program terminates.  I ofter make a CFont object a member 
  50. of my CWnd class.  It's constructed and destroyed with the window. 
  51.  
  52. BTW, check that you're properly destroying those fonts and 
  53. brushes.  Creating them and then not releasing the resources 
  54. can cause a crash as well as a slowdown. 
  55.  
  56. -- 
  57. Pete Grant 
  58. Kalevi, Inc. 
  59. Object Oriented Software Development
  60.